//
//  FFBindUnit.h
//  FFMVVM
//
//  Created by AKsoftware on 2016/11/1.
//  Copyright © 2016年 AKsoftware. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol FFBindProtocol <NSObject>

@property (nonatomic, weak) NSObject *target;
@property (nonatomic, weak) NSObject *observer;
@property (nonatomic, copy) NSString *indentify;

- (void)bind;
- (void)destoryBind;

@end

@interface FFBindUnit : NSObject <FFBindProtocol>

@property (nonatomic, weak) NSObject *target;
@property (nonatomic, weak) NSObject *observer;
@property (nonatomic, copy) NSString *indentify;

//二选一，可以在dispatch_queue_t 中执行，或者选择performThread中执行。
@property (nonatomic, readonly, weak) dispatch_queue_t performQueue;
@property (nonatomic, readonly, weak) NSThread *performThread;

@property (nonatomic, readonly) id performBlock;


- (instancetype)initTarget:(NSObject *)target
                  observer:(NSObject *)observer
                 indentify:(NSString *)indentyfy
             performThread:(NSThread *)thread
              performBlock:(id)block;

- (instancetype)initTarget:(NSObject *)target
                  observer:(NSObject *)observer
                 indentify:(NSString *)indentyfy
              performQueue:(dispatch_queue_t)queue
              performBlock:(id)block;

@end

@interface FFKVOBindUnit : FFBindUnit

@property (nonatomic, readonly) NSString *keyPath;
@property (nonatomic, readonly) NSArray *keyPathArray;
@property (nonatomic, assign) NSKeyValueObservingOptions options;

- (instancetype)initTarget:(NSObject *)target
                  observer:(NSObject *)observer
                   keyPath:(NSArray *)keyPathArray
                   options:(NSKeyValueObservingOptions)options
              performQueue:(dispatch_queue_t)queue
              performBlock:(void(^)(NSString *changeKey, id value))performBlock;

- (instancetype)initTarget:(NSObject *)target
                  observer:(NSObject *)observer
                   keyPath:(NSArray *)keyPathArray
                   options:(NSKeyValueObservingOptions)options
              performThread:(NSThread *)thread
              performBlock:(void(^)(NSString *changeKey, id value))performBlock;
- (void)perfomKvoBlock:(NSString *)key object:(id)value;

@end
